﻿using OMG.Fill.Vegetable.Model.Ent;
using OMG.Fill.Vegetable.Service;
using OMG.Fill.Vegetables.UI;
using ProjectShare;
using System;
using System.Collections.Generic;
using System.Web.Http;
namespace OMG.Fill.Vegetable.Model.UI.Controllers
{
    public class UserController : ApiController
    {
        UserServices userServices = new UserServices();
        
        //[ApiActionAuthorize("获取用户表T_User分页列表对象操作")]
        //[ApiActionException]
        public Pager<List<UserModel>> PostPageList(UserQuery query)

        {
            return userServices.GetPageList(query);
        }
        //[ApiActionAuthorize("新增用户表T_User指定对象操作")]
        //[ApiActionException]
        public ResResult<int> Post(UserEntity model) {
            var user = AppUser.GetUser();
            model.AddUser = AppUser.GetUser().Account;
            model.AddTime = DateTime.Now;
            return userServices.AddInfo(model);
        }
        //[ApiActionAuthorize("修改用户表T_User指定对象操作")]
        //[ApiActionException]
        public ResResult<int> Put(UserEntity model)
        {
            model.UpdateUser = AppUser.GetUser().Account;
            model.UpdateTime = DateTime.Now;
            return userServices.UpdateInfo(model);
        }
        //[ApiActionAuthorize("删除用户表T_User指定对象操作")]
        //[ApiActionException]
        public ResResult<int> Delete(string id)
        {
            return userServices.DeleteInfo(id);
        }
        //[ApiActionAuthorize("获取用户表T_User指定对象操作")]
        //[ApiActionException]
        public ResResult<UserModel> Get(string id)
        {
            return userServices.GetInfo(id);
        }
        /// <summary>
        /// 重置用户密码
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public ResResult<int> ResetPwd(string id)
        {
            return userServices.UpdatePassword(id, 0, "", "");
        }
        /// <summary>
        /// 检查用户名是否存在
        /// </summary>
        /// <param name="Account"></param>
        /// <returns></returns>
        public ResResult<UserEntity> GetCheckAccount(string Account)
        {
            return userServices.GetModel(Account);
        }

        /// <summary>
        /// 修改密码
        /// </summary>
        /// <returns></returns>
        public ResResult<int> PostPassword(UserPasswordModel model)
        {
            return userServices.UpdatePassword(model.UserId, 1, model.Password, model.OriginalPwd);
        }
        /// <summary>
        /// 给用户分配角色
        /// </summary>
        /// <returns></returns>
        //public ResResult<int> UserAwared()
        // {
        //     return userServices.
        // }
    }
}